﻿using Abcd.DistributedCacheTest.ApiHost.Modules;
using Microsoft.Extensions.Caching.StackExchangeRedis;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Caching;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.Modularity;

namespace Abcd.DistributedCacheTest.ApiHost
{
    [DependsOn(
        typeof(AbpAspNetCoreMvcModule),
        //typeof(AbpCachingStackExchangeRedisModule)
        typeof(AbpCachingModule)
        )]
    public class AppModule:AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var services = context.Services;

            Configure<RedisCacheOptions>(options =>
            {
                options.InstanceName = "abcd";
            });

            services.AddControllers();
            services.AddEndpointsApiExplorer();
            services.AddSwaggerGen();
        }

        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var app = (WebApplication) context.GetApplicationBuilder();

            if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            app.UseAuthorization();

            app.MapControllers();
        }
    }
}
